/**
 * Created by json on 2016/9/28.
 */
mj4.HAND_CARD=cc.Node.extend({
    m_isPopEnabled:false,
    m_isPopCheckBox:false,
    m_isPop:false,
    m_oldPosition : null,
    m_isScroll:false,
    m_mjPai:255,
    m_clickCallBack : null,
    ctor: function (mjPai,_isPop,__cb,_target) {
        this._super();
        this.m_clickCallBack = null;
        this.target=_target;
        if(__cb)
        {
            this.m_clickCallBack = __cb;
        }
        this.m_isGuiPai = false;
        this.m_isPopCheckBox = false;
        this.m_isAllowCheck = false;
        this.m_isPop = false;
        this._initCard(mjPai,_isPop);

        var that=this;
        cc.eventManager.addListener({
            event:cc.EventListener.TOUCH_ONE_BY_ONE,
            swallowTouches:false,
            onTouchBegan:function(touch,event){return that.onTouchBegan(touch,event,that);},
            onTouchMoved:function(touch,event){ that.onTouchMoved(touch,event,that);},
            onTouchEnded:function(touch,event){ that.onTouchEnd(touch,event,that);},
            onTouchCancelled:function(touch,event){ that.onTouchCancelled(touch,event,that);},
        },this);
    },
    setClickListener : function(__cb)
    {
        this.m_clickCallBack = __cb;
    },
    _initCard: function (mjPai,_isPop) {
        var that=this;
        if (mjPai == 255)
        {
            this.setVisible(false);
        }
        this.m_isPopEnabled=_isPop;
        this.m_isPop = false;

        this.popHeight = 40;


        var pngStr="#bm.png";

        this.spCard=new cc.Sprite(pngStr);
        this.spCard.attr({
            x:that.width/2,
            y:that.height/2,
            anchorX:0.5,
            anchorY:0.5
        });
        this.addChild(this.spCard);
        this.width=this.spCard.width;
        this.height=this.spCard.height;

        this.spRedDot=new cc.Sprite("res/mj4/reddot.png");
        this.spRedDot.attr({
            x:32,
            y:32,
            anchorX:1.0,
            anchorY:1.0
        });
        this.addChild(this.spRedDot);
        this.spRedDot.setVisible(false);

        this.spTingXuan=new cc.Sprite("res/mj4/ting-biao.png");
        this.spTingXuan.attr({
            x:36,
            y:136,
            anchorX:1.0,
            anchorY:1.0
        });
        this.addChild(this.spTingXuan);
        this.spTingXuan.setVisible(false);

        this.m_oldPosition = cc.p(this.spCard.x,this.spCard.y);
        this.setStandPai(mjPai);

    },
    enablePop: function (bPop) {
        this.m_isPopEnabled=bPop;
    },
    enableCheckBox: function (bPop,_isAllowCheck) {
        this.m_isPopCheckBox=bPop;
        if(bPop) {
            this.m_isAllowCheck = _isAllowCheck;
        }

        if(bPop == false)
        {
            var pos=this.m_oldPosition;
            this.spCard.setPosition(pos);
        }
    },
    setNormalPosition: function (pos) {
        this.m_ptNormal=pos;
    },
    setTing : function(bTing){
        if(bTing)
        {
            this.spCard.setColor(cc.color(255,255,128));
        }else{
            this.spCard.setColor(cc.color(255, 255, 255));
        }
    },
    setDotVisible : function(bVisible)
    {
        this.spRedDot.setVisible(bVisible);
    },
    setTingXuanVisible : function(bVisible)
    {
        this.spTingXuan.setVisible(bVisible);
        if(bVisible)
        {
            this.spHuaZhu.setVisible(false);
        }
    },
    setHuaZhuColor : function(color){
        if(!this.spHuaZhu)
        {
            this.spHuaZhu=new cc.Sprite("res/mj4/huapig.png");
            this.spHuaZhu.attr({
                x:36,
                y:146,
                anchorX:0.5,
                anchorY:0.5
            });
            this.spCard.addChild(this.spHuaZhu);
            this.spHuaZhu.setVisible(false);
            //this.width=this.spHuaZhu.width;
            //this.height=this.spHuaZhu.height;
        }
        var type=parseInt(this.m_mjPai / 9);
        var index=this.m_mjPai - type*9;
        if(this.m_mjPai > 42)
        {
            this.spCard.setVisible(false);
            this.spHuaZhu.setVisible(false);
        }
        if(type == color)
        {
            if(this.spTingXuan.isVisible() == false)
            {
                this.spHuaZhu.setVisible(true);
            }
        }else{
            this.spHuaZhu.setVisible(false);
        }
        //this.spHuaZhu.setVisible(true);
    },
    setGuiPai : function(vecGuiPai,res){
        try {

            this.m_isGuiPai = false;
            if(vecGuiPai && vecGuiPai.length > 0)
            {
                for(var i=0;i<vecGuiPai.length;i++)
                {
                    if(this.m_mjPai == vecGuiPai[i])
                    {
                        this.m_isGuiPai = true;
                    }
                }
            }
            if(this.m_isGuiPai)
            {
                if(!this.spGuiPai)
                {
                    this.spGuiPai=new cc.Sprite(res);
                    this.spGuiPai.attr({
                        x:this.spCard.width,
                        y:this.spCard.height,
                        anchorX:1,
                        anchorY:1
                    });
                    this.spCard.addChild(this.spGuiPai);
                }
                this.spGuiPai.setVisible(true);
            }else{
                if(this.spGuiPai)
                {
                    this.spGuiPai.setVisible(false);
                }
            }
        }catch (e)
        {
            cc.log(e.name + " : " + e.message);
        }
    },
    setPopHeight : function(height){
        this.popHeight = height;
    },
    setStandPai: function (mjPai) {
        if (mjPai == 255)
        {
            this.setVisible(false);
            return;
        }
        this.setVisible(true);
        this.m_isPop = false;
        if (this.m_mjPai != mjPai) {
            var type=parseInt(mjPai / 9);
            var index=mjPai - type*9;

            var pngStr="m_"+(type*10+index+1)+".png";
            if(mjPai == 42)
            {
                pngStr="bm.png";
            }
            this.spCard.initWithSpriteFrameName(pngStr);
        }
        this.setPai(mjPai);
    },
    setPai: function (mjPai) {
        if(mjPai == 255)
        {
            cc.log("setPai:255");
        }
        this.m_mjPai = mjPai;
    },
    getPai: function () {
        return this.m_mjPai;
    },
    onEnter: function () {
        this._super();
    },
    isPop : function()
    {
        if(Math.abs(this.spCard.getPosition().y - this.m_oldPosition.y) < 5)
        {
            this.m_isPop = false;
        }
        if(Math.abs(this.spCard.getPosition().y - this.m_oldPosition.y) >= 30)
        {
            this.m_isPop = true;
        }
        return this.m_isPop;
    },
    onTouchBegan:function(touch,event,that){
        var point=touch.getLocation();
        point=that.convertToNodeSpace(point);

        if (cc.rectContainsPoint(that.spCard.getBoundingBox(), point)){
            if(that.m_isPopEnabled){
                if(that.m_isPopCheckBox == false)
                {
                    var pos=that.m_oldPosition;
                    pos = cc.p(pos.x,pos.y+that.popHeight);
                    that.m_isMove=true;
                    that.spCard.setPosition(pos);
                    that.m_isPop = true;
                }else{
                    if(that.m_isPop == false && this.m_isAllowCheck && this.m_isAllowCheck() == false)
                    {
                        return false;
                    }
                    if(that.m_isPop)
                    {
                        that.m_isPop = false;
                    }else{
                        that.m_isPop = true;
                    }
                    if(that.m_isPop)
                    {
                        var pos=that.m_oldPosition;
                        pos = cc.p(pos.x,pos.y+that.popHeight);
                        that.spCard.setPosition(pos);
                        that.m_isMove=true;
                    }else{
                        var pos = that.m_oldPosition;
                        that.spCard.setPosition(pos);
                        that.m_isMove = false;
                    }
                }

            }
        }
        return true;
    },
    onTouchMoved:function(touch,event,that){
        var point=touch.getLocation();
        point=that.convertToNodeSpace(point);
        if (cc.rectContainsPoint(that.spCard.getBoundingBox(), point)){
            if(that.m_isPopEnabled&&that.m_isMove==false){
                if(that.m_isPopCheckBox == false) {
                    var pos = that.m_oldPosition;
                    pos = cc.p(pos.x, pos.y + that.popHeight);
                    that.spCard.setPosition(pos);
                    that.m_isMove = true;
                    that.m_isPop = true;
                }
            }
        }else if(that.m_isMove==true){
            if(that.m_isPopEnabled){
                if(that.m_isPopCheckBox == false) {
                    var pos = that.m_oldPosition;
                    that.spCard.setPosition(pos);
                    that.m_isMove = false;
                    that.m_isPop = false;
                }else{
                    if(that.m_isPop)
                    {
                        var pos=that.m_oldPosition;
                        pos = cc.p(pos.x,pos.y+that.popHeight);
                        that.spCard.setPosition(pos);
                        that.m_isMove=true;
                    }else{
                        var pos = that.m_oldPosition;
                        that.spCard.setPosition(pos);
                        that.m_isMove = false;
                    }
                }
            }
        }
    },
    onTouchEnd:function(touch,event,that){
        var point=touch.getLocation();
        point=that.convertToNodeSpace(point);
        var ccCrash = that.spCard.getBoundingBox();
        ccCrash.y -= 20;
        ccCrash.height += 30;
        if (cc.rectContainsPoint(ccCrash, point)){
            if(that.m_isPopCheckBox == false) {
                if(that.m_isPopEnabled&&that.m_isMove==true){
                    var pos=that.m_oldPosition;
                    that.spCard.setPosition(pos);
                    that.m_isMove=false;
                    //出牌
                    if(that.m_clickCallBack) {
                        that.m_clickCallBack(that);
                    }
                }
            }else{

            }
        }else if(that.m_isMove==true){
            if(that.m_isPopCheckBox == false) {
                if (that.m_isPopEnabled) {
                    var pos = that.m_oldPosition;
                    that.spCard.setPosition(pos);
                    that.m_isMove = false;
                }
            }
        }

    },
    onTouchCancelled: function (touch,event,that) {
        //出牌
        if(that.m_isPopCheckBox == false) {
            if (that.m_clickCallBack) {
                that.m_clickCallBack(that);
            }
        }
    },


});

mj4.OUT_CARD=cc.Node.extend({
    isCurrent:false,
    ctor: function (seat,mjPai,scale) {
        this._super();
        this.seat = seat;
        this.m_mjPai = mjPai;
        this.m_scale = 1.0;
        if(scale == undefined) {
            this.m_scale = 1.0;
        }else{
            this.m_scale = scale;
        }
        this.m_isGuiPai = false;
        this.isCurrent = false;
        this._initCard(seat,mjPai);

    },
    _initCard: function (seat,mjPai) {
        var that=this;
        if (mjPai == 255)
        {
            this.setVisible(false);

        }


        var picseat = seat;
        if(picseat == 0)
        {
            picseat = 2;
        }


        var pngStr="#bm_0.png";
        if(seat == 0){pngStr = "#bm_0.png";};
        if(seat == 1){pngStr = "#bm_1.png";};
        if(seat == 2){pngStr = "#bm_0.png";};
        if(seat == 3){pngStr = "#bm_3.png";};
        if (mjPai < 34)
        {
            var type=parseInt(mjPai / 9);
            var index=mjPai - type*9;

            pngStr="#" + picseat +"_" +(type*10+index+1)+".png";
        }
        this.spCard=new cc.Sprite(pngStr);
        this.spCard.attr({
            x:that.width/2,
            y:that.height/2,
            anchorX:0.5,
            anchorY:0.5
        });
        this.addChild(this.spCard);
        this.width=this.spCard.width;
        this.height=this.spCard.height;


        this.spCard.setScale(this.m_scale);




        this.arrowSprite=new cc.Sprite("res/mj4/arrow.png");
        this.arrowSprite.setAnchorPoint(0.5,0.5);
        this.arrowSprite.setVisible(false);
        this.spCard.addChild(this.arrowSprite);

        this.setLiePai(mjPai);
    },
    showCurrent: function (currentSprite) {
        //return this;
        currentSprite.setVisible(true);
            //return;
        var pos=this.getPosition();
        if(this.seat == 0 || this.seat == 2)
        {
            currentSprite.setPosition(cc.p(pos.x,pos.y+50));
        }else{
            currentSprite.setPosition(cc.p(pos.x,pos.y+40));
        }

    },
    showNotCurrent: function (currentSprite) {
        //return;
        currentSprite.setVisible(false);
    },
    setArrow : function(bVisible,orientation){
        if(bVisible)
        {
            if(this.seat == 0)
            {
                if(orientation == 0){
                    this.arrowSprite.initWithFile("res/mj4/zimo.png");
                    this.arrowSprite.setPosition(25,30);//this.arrowSprite.rotation=180;
                }else{
                    this.arrowSprite.initWithFile("res/mj4/arrow.png");
                    this.arrowSprite.setPosition(25,30);
                }
                if(orientation == 1){this.arrowSprite.setPosition(25,30);this.arrowSprite.rotation=-90;};
                if(orientation == 2){this.arrowSprite.setPosition(25,30);this.arrowSprite.rotation=180;};
                if(orientation == 3){this.arrowSprite.setPosition(25,30);this.arrowSprite.rotation=90;};
            }
            if(this.seat == 1)
            {
                if(orientation == 1){
                    this.arrowSprite.initWithFile("res/mj4/zimo.png");
                    this.arrowSprite.setPosition(43,25);this.arrowSprite.rotation=-90;
                }else{
                    this.arrowSprite.initWithFile("res/mj4/arrow.png");
                    this.arrowSprite.setPosition(43,25);
                }
                if(orientation == 0){this.arrowSprite.setPosition(43,25);this.arrowSprite.rotation=0;};
                if(orientation == 2){this.arrowSprite.setPosition(43,25);this.arrowSprite.rotation=180;};
                if(orientation == 3){this.arrowSprite.setPosition(43,25);this.arrowSprite.rotation=90;};
            }
            if(this.seat == 2)
            {
                if(orientation == 2){
                    this.arrowSprite.initWithFile("res/mj4/zimo.png");
                    this.arrowSprite.setPosition(23,80);//this.arrowSprite.rotation=180;
                }else{
                    this.arrowSprite.initWithFile("res/mj4/arrow.png");
                    this.arrowSprite.setPosition(23,80);
                }
                if(orientation == 1){this.arrowSprite.setPosition(23,80);this.arrowSprite.rotation=-90;};
                if(orientation == 0){this.arrowSprite.setPosition(23,80);this.arrowSprite.rotation=0;};
                if(orientation == 3){this.arrowSprite.setPosition(23,80);this.arrowSprite.rotation=90;};
            }
            if(this.seat == 3)
            {
                if(orientation == 3){
                    this.arrowSprite.initWithFile("res/mj4/zimo.png");
                    this.arrowSprite.setPosition(0,25);this.arrowSprite.rotation=90;
                }else{
                    this.arrowSprite.initWithFile("res/mj4/arrow.png");
                    this.arrowSprite.setPosition(0,25);
                }
                if(orientation == 1){this.arrowSprite.setPosition(0,25);this.arrowSprite.rotation=-90;};
                if(orientation == 2){this.arrowSprite.setPosition(0,25);this.arrowSprite.rotation=180;};
                if(orientation == 0){this.arrowSprite.setPosition(0,25);this.arrowSprite.rotation=0;};
            }
            this.arrowSprite.setVisible(true);
        }else{
            this.arrowSprite.setVisible(false);
        }
    },
    setTing : function(bTing){
        if(bTing)
        {
            this.spCard.setColor(cc.color(255,255,0));
        }else{
            this.spCard.setColor(cc.color(255, 255, 255));
        }
    },
    setLiePai: function (mjPai) {
        if (mjPai == 255)
        {
            this.setVisible(false);
            return;
        }
        this.setVisible(true);

        if (this.m_mjPai != mjPai) {
            var type=parseInt(mjPai / 9);
            var index=mjPai - type*9;
            var picseat = this.seat;
            if(picseat == 0)
            {
                picseat = 2;
            }

            var pngStr=picseat +"_" +(type*10+index+1)+".png";
            if(mjPai == 42)
            {
                var seat = this.seat;
                pngStr="bm_0.png";
                if(seat == 0){pngStr = "bm_0.png";};
                if(seat == 1){pngStr = "bm_1.png";};
                if(seat == 2){pngStr = "bm_0.png";};
                if(seat == 3){pngStr = "bm_3.png";};
            }

            this.spCard.initWithSpriteFrameName(pngStr);
        }
        this.setPai(mjPai);
    },
    setStandPai: function (mjPai) {
        this.setLiePai(mjPai);
    },
    setPai: function (mjPai) {
        if(mjPai == 255)
        {
            cc.log("setPai:255");
        }
        this.m_mjPai = mjPai;
    },
    getPai: function () {
        return this.m_mjPai;
    },
    setGuiPai : function(vecGuiPai,res){
        try {

            this.m_isGuiPai = false;
            if(vecGuiPai && vecGuiPai.length > 0)
            {
                for(var i=0;i<vecGuiPai.length;i++)
                {
                    if(this.m_mjPai == vecGuiPai[i])
                    {
                        this.m_isGuiPai = true;
                    }
                }
            }
            if(this.m_isGuiPai)
            {
                if(!this.spGuiPai)
                {
                    this.spGuiPai=new cc.Sprite(res);
                    this.spGuiPai.attr({
                        x:this.spCard.width,
                        y:this.spCard.height,
                        anchorX:1,
                        anchorY:1
                    });
                    this.spCard.addChild(this.spGuiPai);
                }
                this.spGuiPai.setVisible(true);
            }else{
                if(this.spGuiPai)
                {
                    this.spGuiPai.setVisible(false);
                }
            }
        }catch (e)
        {
            cc.log(e.name + " : " + e.message);
        }
    },
});
//////////////////////////////////MoveHandCard//////////////////////////////////////////////

mj4.MoveHAND_CARD=cc.Node.extend({
    m_isPopEnabled:false,
    m_isPopCheckBox:false,
    m_isPop:false,
    m_oldPosition : null,
    m_isScroll:false,
    m_mjPai:255,
    m_clickCallBack : null,
    m_cardPrePos:null,
    ctor: function (mjPai,_isPop,__cb,_target) {
        this._super();
        this.m_clickCallBack = null;
        this.target=_target;
        if(__cb)
        {
            this.m_clickCallBack = __cb;
        }
        this.m_isPopCheckBox = false;
        this.m_isAllowCheck = false;
        this.m_isPop = false;
        this._initCard(mjPai,_isPop);

        var that=this;
        cc.eventManager.addListener({
            event:cc.EventListener.TOUCH_ONE_BY_ONE,
            swallowTouches:false,
            onTouchBegan:function(touch,event){return that.onTouchBegan(touch,event,that);},
            onTouchMoved:function(touch,event){ that.onTouchMoved(touch,event,that);},
            onTouchEnded:function(touch,event){ that.onTouchEnd(touch,event,that);},
            onTouchCancelled:function(touch,event){ that.onTouchCancelled(touch,event,that);},


        },this);
    },
    setClickListener : function(__cb)
    {
        this.m_clickCallBack = __cb;
    },
    _initCard: function (mjPai,_isPop) {
        var that=this;
        if (mjPai == 255)
        {
            this.setVisible(false);
        }
        this.m_isGuiPai = false;
        this.m_isPopEnabled=_isPop;
        this.m_isPop = false;

        this.popHeight = 40;


        var pngStr="#bm.png";

        this.spCard=new cc.Sprite(pngStr);
        this.spCard.attr({
            x:that.width/2,
            y:that.height/2,
            anchorX:0.5,
            anchorY:0.5
        });
        this.addChild(this.spCard);
        this.width=this.spCard.width;
        this.height=this.spCard.height;



        this.spRedDot=new cc.Sprite("res/mj4/reddot.png");
        this.spRedDot.attr({
            x:32,
            y:32,
            anchorX:1.0,
            anchorY:1.0
        });
        this.addChild(this.spRedDot);
        this.spRedDot.setVisible(false);

        this.spTingXuan=new cc.Sprite("res/mj4/ting-biao.png");
        this.spTingXuan.attr({
            x:36,
            y:136,
            anchorX:1.0,
            anchorY:1.0
        });
        this.addChild(this.spTingXuan);
        this.spTingXuan.setVisible(false);

        this.m_oldPosition = cc.p(this.spCard.x,this.spCard.y);
        this.setStandPai(mjPai);


    },
    enablePop: function (bPop) {
        this.m_isPopEnabled=bPop;
    },
    enableCheckBox: function (bPop,_isAllowCheck) {
        this.m_isPopCheckBox=bPop;
        if(bPop) {
            this.m_isAllowCheck = _isAllowCheck;
        }

        if(bPop == false)
        {
            var pos=this.m_oldPosition;
            this.spCard.setPosition(pos);
        }
    },
    setNormalPosition: function (pos) {
        this.m_ptNormal=pos;
        this.m_cardPrePos=pos;
    },
    setTing : function(bTing){
        if(bTing)
        {
            this.spCard.setColor(cc.color(255,255,128));
        }else{
            this.spCard.setColor(cc.color(255, 255, 255));
        }
    },
    setDotVisible : function(bVisible)
    {
        this.spRedDot.setVisible(bVisible);
    },
    setTingXuanVisible : function(bVisible)
    {
        this.spTingXuan.setVisible(bVisible);
        if(bVisible && this.spHuaZhu)
        {
            this.spHuaZhu.setVisible(false);
        }
    },
    setHuaZhuColor : function(color){
        if(!this.spHuaZhu)
        {
            this.spHuaZhu=new cc.Sprite("res/mj4/huapig.png");
            this.spHuaZhu.attr({
                x:36,
                y:146,
                anchorX:0.5,
                anchorY:0.5
            });
            this.spCard.addChild(this.spHuaZhu);
            this.spHuaZhu.setVisible(false);
            //this.width=this.spHuaZhu.width;
            //this.height=this.spHuaZhu.height;
        }
        var type=parseInt(this.m_mjPai / 9);
        var index=this.m_mjPai - type*9;
        if(this.m_mjPai > 42)
        {
            this.spCard.setVisible(false);
            this.spHuaZhu.setVisible(false);
        }
        if(type == color)
        {
            if(this.spTingXuan.isVisible() == false)
            {
                this.spHuaZhu.setVisible(true);
            }
        }else{
            this.spHuaZhu.setVisible(false);
        }
        //this.spHuaZhu.setVisible(true);
    },

    setGuiPai : function(vecGuiPai,res){
        try {

            this.m_isGuiPai = false;
            if(vecGuiPai && vecGuiPai.length > 0)
            {
                for(var i=0;i<vecGuiPai.length;i++)
                {
                    if(this.m_mjPai == vecGuiPai[i])
                    {
                        this.m_isGuiPai = true;
                    }
                }
            }
            if(this.m_isGuiPai)
            {
                if(!this.spGuiPai)
                {
                    this.spGuiPai=new cc.Sprite(res);
                    this.spGuiPai.attr({
                        x:this.spCard.width,
                        y:this.spCard.height,
                        anchorX:1,
                        anchorY:1
                    });
                    this.spCard.addChild(this.spGuiPai);
                }
                this.spGuiPai.setVisible(true);
            }else{
                if(this.spGuiPai)
                {
                    this.spGuiPai.setVisible(false);
                }
            }
        }catch (e)
        {
            cc.log(e.name + " : " + e.message);
        }
    },
    setPopHeight : function(height){
        this.popHeight = height;
    },
    setStandPai: function (mjPai) {
        if(mjPai == undefined)
        {
            return;
        }else{

        }
        if (mjPai == 255)
        {
            this.setVisible(false);
            return;
        }
        this.setVisible(true);
        this.m_isPop = false;

        if (this.m_mjPai != mjPai) {
            var type=parseInt(mjPai / 9);
            var index=mjPai - type*9;

            var pngStr="m_"+(type*10+index+1)+".png";
            if(mjPai == 42)
            {
                pngStr="bm_z.png";
            }
			
            this.spCard.initWithSpriteFrameName(pngStr);
        }
        this.setPai(mjPai);
    },
    setPai: function (mjPai) {
        if(mjPai == 255)
        {
            cc.log("setPai:255");
        }
        this.m_mjPai = mjPai;
    },
    getPai: function () {
        return this.m_mjPai;
    },
    onEnter: function () {
        this._super();
    },
    isPop : function()
    {
        if(Math.abs(this.spCard.getPosition().y - this.m_oldPosition.y) < 5)
        {
            this.m_isPop = false;
        }
        if(Math.abs(this.spCard.getPosition().y - this.m_oldPosition.y) >= 30)
        {
            this.m_isPop = true;
        }
        return this.m_isPop;
    },
    onTouchBegan:function(touch,event,that){
        that.isSelect=false;
        var point=touch.getLocation();
        that.startLocation = point;
        point=that.convertToNodeSpace(point);



        if (cc.rectContainsPoint(that.spCard.getBoundingBox(), point))
        {
            if(that.m_isPopEnabled){
                if(that.m_isPopCheckBox == false)
                {
                    that.isSelect=true;

                }else{
                    if(that.m_isPop == false && this.m_isAllowCheck && this.m_isAllowCheck() == false)
                    {
                        return false;
                    }
                    if(that.m_isPop)
                    {
                        that.m_isPop = false;
                    }else{
                        that.m_isPop = true;
                    }
                    if(that.m_isPop)
                    {
                        var pos=that.m_oldPosition;
                        pos = cc.p(pos.x,pos.y+that.popHeight);
                        that.spCard.setPosition(pos);

                    }else{
                        var pos = that.m_oldPosition;
                        that.spCard.setPosition(pos);

                    }
                }
            }
        }
        return true;
    },
    onTouchMoved:function(touch,event,that){
        var point=touch.getLocation();
        var pos = that.m_cardPrePos;
        if(that.m_isPopEnabled){
            if(that.m_isPopCheckBox == false&&that.isSelect==true) {
                that.setPosition(pos.x + point.x-that.startLocation.x,pos.y+point.y-that.startLocation.y);
            }
        }
    },
    onTouchEnd:function(touch,event,that){
        var point=touch.getLocation();
        var pos = that.m_cardPrePos;
        if(that.m_isPopCheckBox == false)
        {
            if(that.m_isPopEnabled&&that.isSelect==true){

                if((point.y-pos.y)>=80){
                    //出牌
                    if(that.m_clickCallBack) {
                        that.m_clickCallBack(that);
                    }
                }else
                {
                    if(that.m_cardPrePos)
                    {
                        that.setPosition(that.m_cardPrePos);
                    }
                }

                //that.setPosition(pos);
                that.isSelect==false;
            }
        }
    },
    onTouchCancelled: function (touch,event,that) {
        //出牌
        if(that.m_cardPrePos)
        {
            that.setPosition(that.m_cardPrePos);
        }
        that.isSelect==false;
    },
    reset_position : function()
    {
        var that = this;
        if(that.m_cardPrePos)
        {
            that.setPosition(that.m_cardPrePos);
        }
    }
});